<?php

use yii\helpers\Url;

$this->title = '中国人事网';
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<div class="appr_sidebar m_left_menu">
    <?= $this->render("@app/views/public/_employeeLeftMenu") ?>
</div>
<div class="appr_bd_wrap">
    <div class="judge_wrap">
        <div class="judge_wrap judge_size_b evaluate_detail">
            <div class="appr_bread">
                <em id="">摘错栏</em>
                <!--懺悔欄-->
            </div>
            <div class="judge_content">
                <div id="grid-list"></div>
            </div>
        </div>
    </div>
</div>
<style>
    .remind-back-color {
        background-color: #5bc0de
    }
</style>
<script type="text/x-kendo-template" id="toolbarTemplate">
    <div id="header-column" style="display: inline">
        <input type="text" style="width:140px;" id="s_date_start" name="s_date_start"
               value="<?= $date['s_date_start'] ?>"
               placeholder="开始月份">
        <input type="text" style="width:140px;" id="s_date_end" name="s_date_end" value="<?= $date['s_date_end'] ?>"
               placeholder="结束月份">
    </div>
    <div id="header-content" style="float:right;display: inline-flex">
        <div id="header-content-one">
            <?php if (!empty($remind['personal'])) { ?>
                <a class="k-button k-button-icontext" style="float: right" onclick="onPersonal();">
                    <span class="glyphicon glyphicon-user"></span> 个人扣款
                    <?php if (isset($remind['EarlyTimeNumber']) && $remind['EarlyTimeNumber'] != 0) echo "<span class='badge remind-back-color'>$remind[EarlyTimeNumber]</span>" ?>
                </a>
            <?php } ?>
            <?php if ($accredit) { ?>
                <a class="k-button k-button-icontext" style="float: right" onclick="onAccredit();">
                    <span class="glyphicon glyphicon-user"></span>授权
                </a>
            <?php } ?>
            <?php if (!empty($remind['departmentTypeEdit'])) { ?>
                <a class="k-button k-button-icontext" style="float: right" onclick="onEditType();"><span
                            class="glyphicon glyphicon-cog"></span>类别设置</a>
            <?php } ?>
            <?php if (!empty($buttonAuth)) { ?>
                <a class="k-button k-button-icontext" style="float: right" onclick="onButtonAuth();"><span
                            class="glyphicon glyphicon-cog"></span>权限</a>
            <?php } ?>
            <a class="k-button k-button-icontext" style="float: right" onclick="onAdd();"><span
                        class="k-icon k-add"></span>发布</a>
        </div>
        <div>
            <?php if ($auth['type'] !== 0) { ?>
                <a class="k-button k-button-icontext" onclick="onTeamEntry();"><span
                            class="glyphicon glyphicon-align-justify"></span> 小组条目
                    <?php
                    $remind['TeamEntryNumber'] = empty($remind['TeamEntryNumber']) ? 0 : $remind['TeamEntryNumber'];
                    $num = $remind['TeamEntryNumber'];
                    if ($num != 0)
                        echo "<span class='badge remind-back-color'>$num</span>";
                    ?>
                </a>
            <?php } ?>
            <?php if($viewAffectedStaff) {?>
                <a class="k-button k-button-icontext" onclick="onAffectedStaff()"><span
                            class="glyphicon glyphicon-th-list"></span> 被影響人
                    <?php if (!empty($affectedStaffNumber)) echo '<span class="badge remind-back-color">' . $affectedStaffNumber . '</span>'; ?>
                </a>
            <?php }?>
            <a class="k-button k-button-icontext" onclick="onPickAffected()"><span
                        class="glyphicon glyphicon-th-list"></span> 績效影響
                <?php if (!empty($pickAffectedNumber)) echo '<span class="badge remind-back-color">' . $pickAffectedNumber . '</span>'; ?>
            </a>
            <?php
            if (!empty($remind['type']))
                echo '<a class="k-button k-button-icontext" onclick="notRatingHistory()"><span class="glyphicon glyphicon-th-list"></span> 未评五大类</a>';
            if (!empty($remind['history']))
                echo '<a class="k-button k-button-icontext" onclick="onHistory()"><span class="glyphicon glyphicon-th-list"></span> 历史</a>';
            ?>
            <a class="k-button k-button-icontext" onclick="onSummary()"><span
                        class="glyphicon glyphicon-th-list"></span> 总汇</a>
        </div>
    </div>
    <div id="header-date" style="display: inline;margin-top: 5px">
        <a class="k-button k-button-icontext" id="onTableList2"
           href="<?= Url::toRoute(["/hr/pick/default/index"]) ?>">
            <span class="glyphicon glyphicon-list-alt"></span> 摘错</a>
        <a class="k-button k-button-icontext" id="onTableList3"
           href="<?= Url::toRoute(["/hr/pick/default/performance"]) ?>">
            <span class="glyphicon glyphicon-list-alt"></span> 绩效</a>
        <a class="k-button k-button-icontext btn btn-info btn-lg active" id="onTableList1">
            <span class="glyphicon glyphicon-list-alt"></span> 摘对</a>
    </div>
</script>
<script>
    var _grid = $("#grid-list"), dataSource, ModifyTimeWindow = $("<div id='ModifyTime-grid'></dib>"),
        editWindow = $("<div id='grid-add'></div>"), alignCenterAttribute = {style: "text-align: center"};
    var addWindow = $("<div id='grid-add'></div>");//发布
    var buttonAuthWindow = $("<div id='grid-button-auth'></div>");//设置
    var departmentTypeEditWindow = $("<div id='grid-department-type-edit'></div>");//部门类别设置
    var personalWindow = $("<div id = 'grid-personal'></div>");//個人條目
    var teamentryWindow = $("<div id='grid-team-entry'></div>");//小組條目
    var notHistoryWindow = $("<div id = 'grid-notHistory'></div>");//未评级历史
    var historyWindow = $("<div id = 'grid-history'></div>");//历史
    var summaryWindow = $("<div id = 'grid-summary'></div>");//总汇
    var accreditWindow = $("<div id = 'grid-accredit'></div>");//授权
    var affectedStaffWindow = $("<div id = 'grid-affected-staff'></div>");//被影響人
    var pickAffectedWindow = $("<div id = 'grid-pick-affected'></div>");//績效影響

    var earlyapplyWindow = $("<div id = 'grid-earlyapply'></div>");

    $(document).ready(function () {
        $("#grid-list").kendoGrid({
            dataSource: {
                transport: {
                    read: function (e) {
                        $.ajax({
                            data: {
                                's_date_start': $("#s_date_start").val(),
                                's_date_end': $("#s_date_end").val(),
                                'column': 1
                            },
                            url: "<?=Url::to(['list']); ?>",
                            type: 'get',
                            dataType: 'json',
                            success: function (res) {
                                e.success(res);
                            }
                        })
                    }
                },
                sort: {field: "created", dir: "desc"},
                schema: {
                    model: {
                        fields: {
                            id: {field: "id", editable: false, nullable: true},
                            created: {field: "created", type: "date"},
                            name_en_long: {field: "name_en_long", type: "string"},
                            name_cn_long: {field: "name_cn_long", type: "string"},
                            content: {field: "content", type: "string"}
                        }
                    }
                },
                pageSize: 40
            },
            dataBinding: function (e) {
                autoHeader();
            },
            sortable: true,
            filterable: {
                extra: false,
                operators: {
                    string: {
                        contains: "包含",
                        doesnotcontain: "不包含",
                        eq: "等于",
                        neq: "不等于"
                    }
                }
            },
            toolbar: kendo.template($("#toolbarTemplate").html()),
            pageable: {
                refresh: true,
                pageSizes: [20, 40, 60, "all"],
                buttonCount: 5
            },
            columns: [
                {
                    field: "created",
                    title: "美国时间",
                    format: "{0:MM/dd/yyyy HH:mm}",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute,
                },
                {
                    field: "department_name",
                    title: "部门",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "group_name",
                    title: "组别",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "name_en_long",
                    title: "英文名",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "name_cn_long",
                    title: "中文名",
                    hidden: true,
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "content",
                    title: "详情",
                    width: "50%"
                }
            ]
        });
        $("#s_date_start").kendoDatePicker({
            format: "yyyy/MM/dd",
            change: function (e) {
                var __grid = $("#grid-list").data("kendoGrid");
                __grid.dataSource.read();
                __grid.refresh();
            }
        });
        $("#s_date_end").kendoDatePicker({
            format: "yyyy/MM/dd",
            change: function (e) {
                var __grid = $("#grid-list").data("kendoGrid");
                __grid.dataSource.read();
                __grid.refresh();
            }
        });
    });

    function autoHeader() {
        var headerWidth = $("#grid-list .k-grid-toolbar").width();
        var headerColumnWidth = $("#header-column").width();
        var headerContentWidth = $("#header-content").width();
        var headerContentHeight = $("#header-content").height();
        var headerDateWidth = $("#header-date").width();
        if (headerWidth < (headerColumnWidth + headerContentWidth + headerDateWidth) || headerContentHeight > 40) {
            $("#header-content").css("display", "block");
            $("#header-content-one").css({display: "inline-block", width: "100%"});
            $("#header-date").css("display", 'block');
            return true;
        }
    }

    function onAdd() {
        if (!addWindow.data("kendoWindow")) {
            addWindow.kendoWindow({
                width: "800",
                height: "400",
                title: "新增条目",
                actions: [
                    "Close"
                ],
                position: {
                    left: "30%",
                    top: "20%"
                }
            }).data("kendoWindow");
        }
        addWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['add']) ?>"
        });
        addWindow.data("kendoWindow").open();
    }

    function onEditType() {
        if (!departmentTypeEditWindow.data("kendoWindow")) {
            departmentTypeEditWindow.kendoWindow({
                width: "800",
                title: "部门类别编辑",
                actions: [
                    "Close"
                ],
                position: {
                    left: "30%",
                    top: "40%"
                }
            }).data("kendoWindow");
        }
        departmentTypeEditWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['departmenttypeedit']) ?>"
        });
        departmentTypeEditWindow.data("kendoWindow").open();
    }

    function onTeamEntry() {
        kendo.ui.progress(teamentryWindow, true);
        if (!teamentryWindow.data("kendoWindow")) {
            teamentryWindow.kendoWindow({
                width: "1600",
                height:"800",
                title: "小组条目",
                actions: [
                    "Close"
                ],
                position:{
                    left:"8%",
                    top:"27%"
                },
                activate: function() {
                },
                close: function(e) {
                    kendo.ui.progress(teamentryWindow, false);
                }
            }).data("kendoWindow");
        }
        teamentryWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['teamentry']) ?>"
        });
        teamentryWindow.data("kendoWindow").open();
    }

    function onSummary() {
        if (!summaryWindow.data("kendoWindow")) {
            summaryWindow.kendoWindow({
                width: "1600",
                height: "800",
                title: "总汇",
                actions: [
                    "Close"
                ],
                position: {
                    left: "8%",
                    top: "27%",
                }
            }).data("kendoWindow");
        }
        summaryWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['summary']) ?>"//Summary
        });
        summaryWindow.data("kendoWindow").open();
    }

    function onPersonal() {
        if (!personalWindow.data("kendoWindow")) {
            personalWindow.kendoWindow({
                width: "1600",
                height: "500",
                title: "个人条目",
                actions: [
                    "Close"
                ],
                position: {
                    left: "8%",
                    top: "27%",
                }
            }).data("kendoWindow");
        }
        personalWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['personal']) ?>"
        });
        personalWindow.data("kendoWindow").open();
    }

    function onHistory() {
        if (!historyWindow.data("kendoWindow")) {
            historyWindow.kendoWindow({
                width: "1600",
                height: "500",
                title: "历史记录",
                actions: [
                    "Close"
                ],
                position: {
                    left: "8%",
                    top: "27%"
                }
            }).data("kendoWindow");
        }
        historyWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['history']) ?>"
        });
        historyWindow.data("kendoWindow").open();
    }

    function onDestroyHistory() {
        if (!historyWindow.data("kendoWindow")) {
            historyWindow.kendoWindow({
                width: "1600",
                height: "500",
                title: "历史记录",
                actions: [
                    "Close"
                ],
                position: {
                    left: "8%",
                    top: "27%"
                }
            }).data("kendoWindow");
        }
        historyWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['destroyhistory']) ?>"
        });
        historyWindow.data("kendoWindow").open();
    }

    function notRatingHistory() {
        if (!notHistoryWindow.data("kendoWindow")) {
            notHistoryWindow.kendoWindow({
                width: "1600",
                height: "800",
                title: "未评五大类历史",
                actions: [
                    "Close"
                ],
                position: {
                    left: "8%",
                    top: "24%"
                }
            }).data("kendoWindow");
        }
        notHistoryWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['notratinghistory']) ?>"
        });
        notHistoryWindow.data("kendoWindow").open();
    }

    function onAccredit() {
        if (!accreditWindow.data("kendoWindow")) {
            accreditWindow.kendoWindow({
                width: "800",
                height: "400",
                title: "我的授权",
                actions: [
                    "Close"
                ],
                position: {
                    left: "28%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        accreditWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['accredit']) ?>"
        });
        accreditWindow.data("kendoWindow").open();
    }

    function onAffectedStaff() {
        kendo.ui.progress(affectedStaffWindow, true);
        if (!affectedStaffWindow.data("kendoWindow")) {
            affectedStaffWindow.kendoWindow({
                width: "1412px",
                height: "760",
                title: "被影響人",
                actions: [
                    "Close"
                ],
                position: {
                    left: "338px",
                    top: "236px"
                }
            }).data("kendoWindow");
        }
        affectedStaffWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showaffectedstaff']) ?>"
        });
        affectedStaffWindow.data("kendoWindow").open();
    }

    function onPickAffected() {
        if (!pickAffectedWindow.data("kendoWindow")) {
            pickAffectedWindow.kendoWindow({
                width: "1412px",
                height: "760",
                title: "績效影響",
                actions: [
                    "Close"
                ],
                position: {
                    left: "338px",
                    top: "236px"
                }
            }).data("kendoWindow");
        }
        pickAffectedWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showpickaffected']) ?>"
        });
        pickAffectedWindow.data("kendoWindow").open();
    }

    /**
     * 管理
     */
    function onButtonAuth() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "18%",
                    top: "25%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['buttonauth']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onLeaderAuth() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['agent']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onNotCommented() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['shownotcommentedfivestype']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onHistoryRecord() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showhistoryrecord']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onSummaryMaintain() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showsummarymaintain']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onSummaryManagement() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showsummarymanagement']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onAuthManagement() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showauthmanagement']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onRatingSettings() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "权限分配",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showratingsettings']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    function onAffectPrincipal() {
        if (!buttonAuthWindow.data("kendoWindow")) {
            buttonAuthWindow.kendoWindow({
                width: "1400",
                height: "760",
                title: "被影響人負責人",
                actions: [
                    "Close"
                ],
                position: {
                    left: "15%",
                    top: "28%"
                }
            }).data("kendoWindow");
        }
        buttonAuthWindow.data("kendoWindow").refresh({
            url: "<?=Url::to(['showaffectprincipal']) ?>"
        });
        buttonAuthWindow.data("kendoWindow").open();
    }

    /**
     * 通用
     */
    function gridRefresh(id) {
        var grid = $("#" + id).data('kendoGrid');
        grid.dataSource.read();
        grid.refresh();
    }
</script>
